package com.google.code.hibernate.rest.impl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;

import javax.servlet.ServletOutputStream;

/**
 * 
 * @author wangzijian
 * 
 */
class ByteArrayServletOutputStream extends ServletOutputStream {

	private final ByteArrayOutputStream outputStream;

	public ByteArrayServletOutputStream() {
		outputStream = new ByteArrayOutputStream();
	}

	@Override
	public void write(int b) throws IOException {
		outputStream.write(b);
	}

	public byte[] toByteArray() {
		return outputStream.toByteArray();
	}

	public String toString(Charset encoding) {
		return new String(toByteArray(), encoding);
	}
	
	
}
